var App = require('app');

App.RateDisplayView = Em.View.extend({
    templateName: require('templates/field/rate/display'),
    didInsertElement: function() {
		$(".icon-star-empty").on({
			click: function() {
				var stars = $(".icon-star");
				stars.each(function(index, domEle){
					$(domEle).removeClass("icon-star");
					$(domEle).addClass("icon-star-empty");
				});
				$(this).removeClass("icon-star-empty");
				$(this).addClass("icon-star");
				
				var rate = $(this).attr("data-value");
				var formId = $("input#formId").val();
				var formKey = $("input#formKey2").attr("name");		
				$.ajax({
					type : 'GET',
					dataType : 'json', contentType: "application/json",
					async : false,
					url : Vari.ApiRestV1 + 'form/rate',
					data : {
						rate: rate,
						formId: formId,
						formKey: formKey
					},
					success : function(json) {
						new $.Zebra_Dialog('<strong>Sucess</strong> to submit the data!', {
						    'buttons':  false,
						    'modal': false,
						    'position': [],
						    'auto_close': 1000
						});	
					}
				});
				
				return false;
			}
		});
    }
});